﻿using System;
using System.Diagnostics;
using System.IO;

namespace uREST.Core.Extensions
{
    public static class StreamExtensions
    {
        public static void WriteTo(this Stream src, Stream dest)
        {
            if (src == null)
                throw new ArgumentNullException("src");
            if (dest == null)
                throw new ArgumentNullException("dest");

            Debug.Assert(src.CanRead, "src.CanRead");
            Debug.Assert(dest.CanWrite, "dest.CanWrite");

            int readCount;
            var buffer = new byte[8192];

            if (src.CanSeek)
                src.Seek(0, SeekOrigin.Begin);

            while ((readCount = src.Read(buffer, 0, buffer.Length)) != 0)
                dest.Write(buffer, 0, readCount);
        }
    }
}
